package com.yyn.seckill.service.impl;

import com.yyn.seckill.entity.Goods;
import com.yyn.seckill.entity.dto.GoodDetialListDto;
import com.yyn.seckill.entity.dto.GoodListDto;
import com.yyn.seckill.mapper.GoodsMapper;
import com.yyn.seckill.service.GoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yyn.seckill.vo.R;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author yyn
 * @since 2023-01-21
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {

    @Override
    public List<GoodListDto> goodList() {
        List<GoodListDto> goodListDtos = baseMapper.goodList();
        return goodListDtos;
    }

    @Override
    public GoodDetialListDto goodDetialList(String goodId) {
        GoodDetialListDto goodDetialListDtos = baseMapper.goodDetialList(goodId);
        return goodDetialListDtos;
    }

    @Override
    public Map goodsSkill(String goodId) {
        GoodDetialListDto goodDetialListDtos = baseMapper.goodDetialList(goodId);
//        秒杀的时间
            Date startDate = goodDetialListDtos.getStartDate();
        Date endDate = goodDetialListDtos.getEndDate();
        Date date = new Date();
        Long timeDown= 0L;
        int status=0;
        if(date.before(startDate)){
            status=0;
            timeDown=  (startDate.getTime()-date.getTime()/1000);
        }else if(date.after(startDate)){
            status=2;
        }else {
            status=1;
        }
        Map<String, Object> stringStringMap = new HashMap<>();
        stringStringMap.put("startDate", String.valueOf(startDate));
        stringStringMap.put("endDate", String.valueOf(endDate));
        stringStringMap.put("status", String.valueOf(status));
        stringStringMap.put("timeDown", String.valueOf(timeDown));
        return  stringStringMap;
    }
}
